home *** CD-ROM | disk | FTP | other *** search
/ PC/CD Gamer UK 120 / CD Gamer Issue 120 (March 2003) (Disc 2).ISO / mods / Q2_Codered / codeRED1_0.exe / Data1.cab / r_misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-09-20  |  7.3 KB  |  266 lines

  1. /*
  2. Copyright (C) 1997-2001 Id Software, Inc.
  3.  
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
  12.  
  13. See the GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. */
  20. // r_misc.c
  21.  
  22. #include "r_local.h"
  23.  
  24. /*
  25. ==================
  26. R_InitParticleTexture
  27. ==================
  28. */
  29. byte    dottexture[16][16] =
  30. {
  31.     {0,0,0,0,0,2,6,7,7,5,2,0,0,0,0,0},
  32.     {0,0,0,1,8,20,33,40,39,30,18,7,0,0,0,0},
  33.     {0,0,1,12,35,60,78,87,87,76,56,30,10,0,0,0},
  34.     {0,0,9,37,72,103,125,136,135,122,98,67,31,7,0,0},
  35.     {0,3,25,66,108,142,168,180,179,164,137,102,60,20,2,0},
  36.     {0,9,44,91,137,175,206,220,219,201,170,130,84,38,6,0},
  37.     {0,15,58,109,157,200,233,249,248,229,194,150,101,51,11,0},
  38.     {1,18,66,118,167,212,245,254,254,242,206,159,110,57,14,0},
  39.     {1,18,64,116,165,209,243,254,254,239,203,158,108,56,13,0},
  40.     {0,13,54,104,152,193,225,242,240,221,187,144,97,47,9,0},
  41.     {0,7,39,84,128,165,194,209,207,190,160,122,77,32,5,0},
  42.     {0,2,20,57,97,130,154,167,166,152,125,91,51,15,1,0},
  43.     {0,0,6,27,60,89,111,121,120,108,85,55,23,5,0,0},
  44.     {0,0,0,7,24,46,63,72,72,61,43,20,6,0,0,0},
  45.     {0,0,0,0,4,11,20,26,26,20,10,3,0,0,0,0},
  46.     {0,0,0,0,0,0,2,3,3,2,0,0,0,0,0,0},
  47. };   
  48.  
  49. void R_InitParticleTexture (void)
  50. {
  51.     int        x,y;
  52.     byte    data[16][16][4];
  53.     //
  54.     // particle texture
  55.     //
  56.     for (x=0 ; x<16 ; x++) 
  57.     {
  58.         for (y=0 ; y<16 ; y++)
  59.         {
  60.             data[y][x][0] = 255;
  61.             data[y][x][1] = 255;
  62.             data[y][x][2] = 255;
  63.             data[y][x][3] = dottexture[x][y]; // c14 Just this line changes
  64.         }
  65.     }
  66.     r_particletexture = GL_LoadPic ("***particle***", (byte *)data, 16, 16, it_sprite, 32);
  67.  
  68.     r_smoketexture = R_RegisterParticlePic("smoke");//etc etc etc...
  69.     r_particletexture = R_RegisterParticlePic("particle");   
  70.     r_explosiontexture = R_RegisterParticlePic("explosion");
  71.     r_bloodtexture = R_RegisterParticlePic("blood");
  72.     r_pufftexture = R_RegisterParticlePic("puff");
  73.     r_blastertexture = R_RegisterParticlePic("blaster");
  74.     r_bflashtexture = R_RegisterParticlePic("bflash");
  75.     r_leaderfieldtexture = R_RegisterParticlePic("leaderfield");
  76.     r_shelltexture = R_RegisterParticlePic("shell");
  77.     if (!r_particletexture) {                                 //c14 add this line
  78.         r_particletexture = GL_LoadPic ("***particle***", (byte *)data, 16, 16, it_sprite, 32);
  79.     }                                                         //c14 add this line  
  80.     
  81.     //
  82.     // also use this for bad textures, but without alpha
  83.     //
  84.     for (x=0 ; x<16 ; x++)
  85.     {
  86.         for (y=0 ; y<16 ; y++)
  87.         {
  88.             data[y][x][0] = dottexture[x&3][y&3]*255;
  89.             data[y][x][1] = 0; // dottexture[x&3][y&3]*255;
  90.             data[y][x][2] = 0; //dottexture[x&3][y&3]*255;
  91.             data[y][x][3] = 255;
  92.         }
  93.     }
  94.     r_notexture = GL_LoadPic ("***r_notexture***", (byte *)data, 16, 16, it_wall, 32);
  95. }
  96.  
  97.  
  98. /* 
  99. ============================================================================== 
  100.  
  101.                         SCREEN SHOTS 
  102.  
  103. ============================================================================== 
  104. */ 
  105.  
  106. typedef struct _TargaHeader {
  107.     unsigned char     id_length, colormap_type, image_type;
  108.     unsigned short    colormap_index, colormap_length;
  109.     unsigned char    colormap_size;
  110.     unsigned short    x_origin, y_origin, width, height;
  111.     unsigned char    pixel_size, attributes;
  112. } TargaHeader;
  113.  
  114.  
  115. /* 
  116. ================== 
  117. GL_ScreenShot_f
  118. ================== 
  119. */  
  120. void GL_ScreenShot_f (void) 
  121. {
  122.     byte        *buffer;
  123.     char        picname[80]; 
  124.     char        checkname[MAX_OSPATH];
  125.     int            i, c, temp;
  126.     FILE        *f;
  127.  
  128.     // create the scrnshots directory if it doesn't exist
  129.     Com_sprintf (checkname, sizeof(checkname), "%s/scrnshot", FS_Gamedir());
  130.     Sys_Mkdir (checkname);
  131.  
  132. // 
  133. // find a file name to save it to 
  134. // 
  135.     strcpy(picname,"codered00.tga");
  136.  
  137.     for (i=0 ; i<=99 ; i++) 
  138.     { 
  139.         picname[5] = i/10 + '0'; 
  140.         picname[6] = i%10 + '0'; 
  141.         Com_sprintf (checkname, sizeof(checkname), "%s/scrnshot/%s", FS_Gamedir(), picname);
  142.         f = fopen (checkname, "rb");
  143.         if (!f)
  144.             break;    // file doesn't exist
  145.         fclose (f);
  146.     } 
  147.     if (i==100) 
  148.     {
  149.         Com_Printf ("SCR_ScreenShot_f: Couldn't create a file\n"); 
  150.         return;
  151.      }
  152.  
  153.  
  154.     buffer = malloc(vid.width*vid.height*3 + 18);
  155.     memset (buffer, 0, 18);
  156.     buffer[2] = 2;        // uncompressed type
  157.     buffer[12] = vid.width&255;
  158.     buffer[13] = vid.width>>8;
  159.     buffer[14] = vid.height&255;
  160.     buffer[15] = vid.height>>8;
  161.     buffer[16] = 24;    // pixel size
  162.  
  163.     qglReadPixels (0, 0, vid.width, vid.height, GL_RGB, GL_UNSIGNED_BYTE, buffer+18 ); 
  164.  
  165.     // swap rgb to bgr
  166.     c = 18+vid.width*vid.height*3;
  167.     for (i=18 ; i<c ; i+=3)
  168.     {
  169.         temp = buffer[i];
  170.         buffer[i] = buffer[i+2];
  171.         buffer[i+2] = temp;
  172.     }
  173.  
  174.     f = fopen (checkname, "wb");
  175.     fwrite (buffer, 1, c, f);
  176.     fclose (f);
  177.  
  178.     free (buffer);
  179.     Com_Printf ("Wrote %s\n", picname);
  180.  
  181. /*
  182. ** GL_Strings_f
  183. */
  184. void GL_Strings_f( void )
  185. {
  186.     Com_Printf ("GL_VENDOR: %s\n", gl_config.vendor_string );
  187.     Com_Printf ("GL_RENDERER: %s\n", gl_config.renderer_string );
  188.     Com_Printf ("GL_VERSION: %s\n", gl_config.version_string );
  189.     Com_Printf ("GL_EXTENSIONS: %s\n", gl_config.extensions_string );
  190. }
  191.  
  192. /*
  193. ** GL_SetDefaultState
  194. */
  195. void GL_SetDefaultState( void )
  196. {
  197.     qglClearColor (1,0, 0.5 , 0.5);
  198.     qglCullFace(GL_FRONT);
  199.     qglEnable(GL_TEXTURE_2D);
  200.  
  201.     qglEnable(GL_ALPHA_TEST);
  202.     qglAlphaFunc(GL_GREATER, 0.666);
  203.  
  204.     qglDisable (GL_DEPTH_TEST);
  205.     qglDisable (GL_CULL_FACE);
  206.     qglDisable (GL_BLEND);
  207.  
  208.     qglColor4f (1,1,1,1);
  209.  
  210.     qglPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
  211.     qglShadeModel (GL_FLAT);
  212.  
  213.     GL_TextureMode( gl_texturemode->string );
  214.     GL_TextureAlphaMode( gl_texturealphamode->string );
  215.     GL_TextureSolidMode( gl_texturesolidmode->string );
  216.  
  217.     qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_min);
  218.     qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max);
  219.  
  220.     qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  221.     qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  222.  
  223.     qglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  224.  
  225.     GL_TexEnv( GL_REPLACE );
  226.  
  227.     if ( qglPointParameterfEXT )
  228.     {
  229.         float attenuations[3];
  230.  
  231.         attenuations[0] = gl_particle_att_a->value;
  232.         attenuations[1] = gl_particle_att_b->value;
  233.         attenuations[2] = gl_particle_att_c->value;
  234.  
  235.         qglEnable( GL_POINT_SMOOTH );
  236.         qglPointParameterfEXT( GL_POINT_SIZE_MIN_EXT, gl_particle_min_size->value );
  237.         qglPointParameterfEXT( GL_POINT_SIZE_MAX_EXT, gl_particle_max_size->value );
  238.         qglPointParameterfvEXT( GL_DISTANCE_ATTENUATION_EXT, attenuations );
  239.     }
  240.  
  241.     if ( qglColorTableEXT && gl_ext_palettedtexture->value )
  242.     {
  243.         qglEnable( GL_SHARED_TEXTURE_PALETTE_EXT );
  244.  
  245.         GL_SetTexturePalette( d_8to24table );
  246.     }
  247.  
  248.     GL_UpdateSwapInterval();
  249. }
  250.  
  251. void GL_UpdateSwapInterval( void )
  252. {
  253.     if ( gl_swapinterval->modified )
  254.     {
  255.         gl_swapinterval->modified = false;
  256.  
  257.         if ( !gl_state.stereo_enabled ) 
  258.         {
  259. #ifdef _WIN32
  260.             if ( qwglSwapIntervalEXT )
  261.                 qwglSwapIntervalEXT( gl_swapinterval->value );
  262. #endif
  263.         }
  264.     }
  265. }